package tq.com.tqteacher.discuss.vh;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import tq.com.tqteacher.R;
import tq.com.tqteacher.model.TQCommentOverInfoModel;

public class TQSelectRightViewHold extends TQRightViewHold {
    public static TQSelectRightViewHold instance(Context pContext, ViewGroup pViewGroup){
        View lView = LayoutInflater.from(pContext).inflate(R.layout.vh_discuss_right, pViewGroup, false);
        return new TQSelectRightViewHold(lView);
    }

    private ImageButton mImageButton;
    public TQSelectRightViewHold(View pView){
        super(pView);

        mImageButton = pView.findViewById(R.id.btn_check);
        mImageButton.setVisibility(View.VISIBLE);

        mImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mImageButton.setSelected(!mImageButton.isSelected());

                if(mIDiscussItemClickListener != null){
                    ((IDiscussSelectItemClickListener)mIDiscussItemClickListener).selectMessage(mCommentInfoModel,
                            mImageButton.isSelected());
                }
            }
        });


    }

    public void bindData(TQCommentOverInfoModel.TQCommentInfoModel pInfoModel){
        super.bindData(pInfoModel);

        if(mIDiscussItemClickListener != null && mIDiscussItemClickListener instanceof IDiscussSelectItemClickListener){
            boolean isSelected = ((IDiscussSelectItemClickListener)mIDiscussItemClickListener).isSelected(mCommentInfoModel);
            mImageButton.setSelected(isSelected);
        }

    }
}
